package com.cndw.kungfu.dao;

import java.util.Map;

import com.cndw.dao.jade.Identity;
import com.cndw.dao.jade.annotation.DAO;
import com.cndw.dao.jade.annotation.KeyColumnOfMap;
import com.cndw.dao.jade.annotation.SQL;
import com.cndw.dao.jade.annotation.SQLParam;
import com.cndw.kungfu.domain.Collect;
import com.cndw.kungfu.domain.PlayerOffline;

/**
 * 通用模块dao
 * 
 * 
 * @author <a href="mailto:whz-work@163.com">汪洪州</a>
 * 
 * @since 1.0 Create on 2011-8-2
 */
@DAO
public interface GeneralDao {

	public static final String PLAYER_OFFLINE_TABLE = " kf_player_offline_exp ";
	public static final String PLAYER_OFFLINE_FIELD = " playerId,goodsId,getTime ";

	public static final String COLLECT_TABLE = " kfsys_collect ";
	public static final String COLLECT_FIELD = " id,type,name,goodsId1,counts1,goodsId2,counts2,goodsId3,counts3,goodsId4,counts4,goodsId5,counts5,goodsId,counts,points,reiteration ";

	public static final String PLAYER_COLLECT_TABLE = " kf_player_collect ";
	public static final String PLAYER_COLLECT_FIELD = " playerId,collectId,exchange,lastTime ";

	@SQL("select count(*) from " + PLAYER_OFFLINE_TABLE + "where playerId=:1 and getTime >= :2")
	public int getOfflineExpTodayCounts(long playerId, int getTime);

	@SQL("insert into " + PLAYER_OFFLINE_TABLE + " (" + PLAYER_OFFLINE_FIELD + ") values(:offline.playerId,:offline.goodsId,:offline.getTime)")
	public Identity addOfflineExp(@SQLParam("offline") PlayerOffline offline);

	@KeyColumnOfMap("id")
	@SQL("select " + COLLECT_FIELD + " from " + COLLECT_TABLE)
	public Map<Integer, Collect> getAllCollect();

	@SQL("select count(*) from " + PLAYER_COLLECT_TABLE + "where playerId=:1 and collectId = :2")
	public int checkCollectFinish(long playerId, int collectId);

	@SQL("insert into " + PLAYER_COLLECT_TABLE + " (" + PLAYER_COLLECT_FIELD + ") values(:1,:2,1,UNIX_TIMESTAMP())")
	public void addPlayerCollect(long playerId, int collectId);

	@SQL("update " + PLAYER_COLLECT_TABLE + " set exchange=exchange+1 where playerId=:1 and collectId >= :2")
	public boolean increasePlayerCollect(long playerId, int collectId);

}
